package com.work.demo.rabbitmq.routing;

import com.work.demo.rabbitmq.utils.RabbitConstant;
import com.work.demo.rabbitmq.utils.RabbitUtils;
import com.rabbitmq.client.*;

import java.io.IOException;

/**
 * @ClassName : Sina
 * @Description : 消费者1-新浪
 * @Author : LinYa
 * @Date: 2022/1/12  16:38
 */
public class Sina {

	public static void main(String[] args) throws IOException {
		Connection connection = RabbitUtils.getConnection();
		final Channel channel = connection.createChannel();

		channel.queueDeclare(RabbitConstant.QUEUE_SINA, false, false, false, null);

		channel.queueBind(RabbitConstant.QUEUE_SINA, RabbitConstant.EXCHANGE_WEATHER_ROUTING, "china.henan.zhengzhou.20201128");
		channel.queueBind(RabbitConstant.QUEUE_SINA, RabbitConstant.EXCHANGE_WEATHER_ROUTING, "us.cal.lsj.20201128");

		channel.basicQos(1);

		channel.basicConsume(RabbitConstant.QUEUE_SINA, false, new DefaultConsumer(channel) {
			@Override
			public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
				System.out.println("新浪天气收到气象信息：" + new String(body));
				channel.basicAck(envelope.getDeliveryTag(), false);
			}
		});
	}
}
